package com.cqut.hfh.ordering.service.Impl;

import com.cqut.hfh.ordering.pojo.FoodDetail;
import com.cqut.hfh.ordering.pojo.FoodIndent;
import com.cqut.hfh.ordering.service.IFodDetailService;
import com.cqut.li.mybatisutil.dao.base.Dao;
import com.cqut.li.mybatisutil.dao.base.SearchDao;
import com.cqut.li.mybatisutil.entity.base.Entity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author LJH
 * @date 2019/6/25-21:49
 */
@Service
public class FodDetailServiceImpl implements IFodDetailService {

    @Resource
    private SearchDao searchDao;
    @Resource
    private Dao dao;


    @Override
    public List<Map<String, Object>> getDetails(String limit, String page, String indent_id) {
        String joinEntity
                = " left join fod_food on fod_food.food_id = fod_detail.food_id "
                + " left join fod_indent on fod_detail.indent_id = fod_indent.indent_id ";
        String con = " 1=1 limit "+ (Integer.valueOf(page)-1)*Integer.valueOf(limit) + "," + limit ;

        List<Map<String, Object>> fi_list
                = searchDao.searchForeign(new String[]{"fod_detail.detail_id",
                        "fod_indent.indent_name",
                        "fod_food.food_name",
                        "fod_detail.food_price",
                        "fod_detail.food_num",
                        "fod_detail.isva",
                        "fod_detail.oper",
                        "fod_detail.optime"},
                Entity.getTableName(FoodDetail.class),
                joinEntity,
                null,
                null,
                con);


        return fi_list;
    }

    @Override
    public Integer getCount() {
        String joinEntity
                = " left join fod_food on fod_food.food_id = fod_detail.food_id "
                + " left join fod_indent on fod_detail.indent_id = fod_indent.indent_id ";

        List<Map<String, Object>> fi_list
                = searchDao.searchForeign(new String[]{"fod_detail.detail_id"},
                Entity.getTableName(FoodDetail.class),
                joinEntity,
                null,
                null,
                null);
        return fi_list.size();
    }
}
